package notify

import (
	_ "embed"
	"fmt"
	"github.com/CatchZeng/feishu/pkg/feishu"
	"log"
	"time"
)

//go:embed feishu_card.json
var feiShuContent string

func sendDrinkMessage(client *feishu.Client) {
	msg := feishu.NewInteractiveMessage()

	t := time.Now()
	tf := t.Format("2006-01-02 15:04:05")
	msg.MsgType = "interactive"

	const card string = `{
  "header": {
    "title": {
      "tag": "plain_text",
      "content": "📣 候选人沟通提醒  %s "
    },
    "template": "wathet"
  },
  "elements": [
    {
      "tag": "div",
      "text": {
        "content": "朋友们，记得喝水哦！喝水有助于保持健康、清醒、高效。站起来喝一杯吧！",
        "tag": "lark_md"
      }
    },
    {
      "tag": "markdown",
      "content": "\n查看 [喝水秘籍](https://www.bilibili.com/video/BV1Gh411p72E/?spm_id_from=333.337.search-card.all.click) <at id=all></at>"
    }
  ]
}`
	msg.Card = fmt.Sprintf(card, tf)

	_, resp, err := client.Send(msg)
	if err != nil {
		log.Print(err)
		return
	}
	log.Print(resp)
}
func sendNotify(client *feishu.Client) {
	msg := feishu.NewInteractiveMessage()

	t := time.Now()
	tf := t.Format("2006-01-02 15:04:05")
	msg.MsgType = "interactive"

	msg.Card = fmt.Sprintf(feiShuContent, tf)
	_, resp, err := client.Send(msg)
	if err != nil {
		log.Print(err)
		return
	}
	log.Print(resp)
}

func sendPlainMessage(client *feishu.Client) {
	msg := feishu.NewTextMessage()
	msg.Content.Text = "Hello, world!"
	_, resp, err := client.Send(msg)
	if err != nil {
		log.Print(err)
		return
	}
	log.Print(resp)
}

func Send() {
	token := "fc7127b6-3e6b-48c5-b3ed-994378e6fc31"
	secret := "gfabwJ4j2lQ9TIb4Sp1BUf"

	client := feishu.NewClient(token, secret)
	sendNotify(client)
	//sendPlainMessage(client)
	//sendDrinkMessage(client)
}
